package com.cn.aam.checaiduo.ui.me.adapter;

import android.content.Context;
import android.graphics.Color;
import android.support.v4.content.ContextCompat;
import android.text.TextUtils;
import android.view.View;
import android.widget.TextView;

import com.cn.aam.checaiduo.R;
import com.cn.aam.checaiduo.base.adapter.BaseRecycerAdapter;
import com.cn.aam.checaiduo.base.adapter.holder.BaseRecyclerViewHolder;
import com.cn.aam.checaiduo.bean.me.PointDetailB;

import java.util.List;

import butterknife.BindView;

/**
 * monker on 2017/6/20.
 */

public class PointDetailChildAdapter extends BaseRecycerAdapter<PointDetailB> {

    public PointDetailChildAdapter(Context mContext) {
        super(mContext);
    }

    @Override
    protected BaseRecyclerViewHolder getViewHolder(View picNewsView) {
        return new PointDetailChildHolder(picNewsView);
    }

    @Override
    public void addData(List<PointDetailB> data) {
        if (data == null || data.size() == 0) {
            return;
        }

        getDataList().clear();
        getDataList().addAll(data);
        notifyDataSetChanged();
    }

    @Override
    protected int getItemLayoutRes() {
        return R.layout.list_point_detail_child_item;
    }

    @Override
    protected void ItemVIewChange(BaseRecyclerViewHolder recyclerholder, int position) {
        PointDetailChildHolder holder = (PointDetailChildHolder) recyclerholder;
        holder.childTvDay.setText(getDay(getItem(position).getCreated_time()));
        holder.childTvType.setText(getItem(position).getType());

        if (!TextUtils.equals(getItem(position).getIncome(), "0")) {
            holder.childTvExpense.setText("+ " + getItem(position).getIncome());
            holder.childTvExpense.setTextColor(ContextCompat.getColor(mContext, R.color.colorPrimary));

        } else {
            holder.childTvExpense.setText("- " + getItem(position).getExpense());
            holder.childTvExpense.setTextColor(Color.parseColor("#605F87"));
        }
        if (position == getDataList().size() - 1) {
            holder.line.setVisibility(View.GONE);
        } else {
            holder.line.setVisibility(View.VISIBLE);
        }
    }


    private String getDay(String str) {
        str = str.split(" ")[0];
        str = str.substring(str.lastIndexOf("-") + 1, str.length());
        return str + "日";
    }

    class PointDetailChildHolder extends BaseRecyclerViewHolder {
        @BindView(R.id.child_tv_day)
        TextView childTvDay;
        @BindView(R.id.child_tv_type)
        TextView childTvType;
        @BindView(R.id.child_tv_expense)
        TextView childTvExpense;
        @BindView(R.id.line)
        View line;

        public PointDetailChildHolder(View itemView) {
            super(itemView);
        }
    }
}
